<template>
	<view class="body">
		<!-- 操作菜单 -->
		<paper-left-popup :show="show" @hide="hiddenPopup" @addFriend="addFriend" @clear="clear">
		</paper-left-popup>
		<!-- 小纸条列表 -->
		<block v-for="(item,index) in list" :key="index">
			<paper-list :item="item" :index="index"></paper-list>
		</block>
		<!-- 上拉加载 -->
		<load-more :loadtext="loadtext"></load-more>
	</view>
</template>

<script>
	import paperList from "../../components/paper/paper-list.vue";
	import loadMore from "../../components/common/load-more.vue";
	import paperLeftPopup from "../../components/paper/paper-left-popup.vue";
	export default {
		components: {
			paperList,
			loadMore,
			paperLeftPopup
		},
		data() {
			return {
				show: false,
				loadtext: "上拉加载更多",
				list: [{
						userpic: "../../static/demo/userpic/10.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 2
					},
					{
						userpic: "../../static/demo/userpic/15.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 0
					},
					{
						userpic: "../../static/demo/userpic/14.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 0
					},
					{
						userpic: "../../static/demo/userpic/13.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 11
					},
					{
						userpic: "../../static/demo/userpic/13.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 11
					},
					{
						userpic: "../../static/demo/userpic/13.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 11
					},
					{
						userpic: "../../static/demo/userpic/13.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 11
					},
					{
						userpic: "../../static/demo/userpic/13.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 11
					},
					{
						userpic: "../../static/demo/userpic/13.jpg",
						username: "昵称",
						time: "10:21",
						data: "我是信息",
						noreadnum: 11
					}
				]
			}
		},
		methods: {
			addFriend() {
				console.log("添加好友");
				this.show = false;
			},
			clear() {
				console.log("清除缓存");
				this.show = false;
			},
			hiddenPopup() {
				this.show = false;
			},
			showPopup() {
				this.show = true;
			},
			getData() {
				setTimeout(() => {
					let arr = [{
							userpic: "../../static/demo/userpic/10.jpg",
							username: "昵称1",
							time: "10:21",
							data: "我是信息",
							noreadnum: 2
						},
						{
							userpic: "../../static/demo/userpic/15.jpg",
							username: "昵称2",
							time: "10:21",
							data: "我是信息",
							noreadnum: 0
						},
						{
							userpic: "../../static/demo/userpic/14.jpg",
							username: "昵称3",
							time: "10:21",
							data: "我是信息",
							noreadnum: 0
						},
						{
							userpic: "../../static/demo/userpic/13.jpg",
							username: "昵称4",
							time: "10:21",
							data: "我是信息",
							noreadnum: 11
						},
						{
							userpic: "../../static/demo/userpic/11.jpg",
							username: "昵称4",
							time: "10:21",
							data: "我是信息",
							noreadnum: 11
						},
						{
							userpic: "../../static/demo/userpic/12.jpg",
							username: "昵称4",
							time: "10:21",
							data: "我是信息",
							noreadnum: 11
						},
						{
							userpic: "../../static/demo/userpic/13.jpg",
							username: "昵称4",
							time: "10:21",
							data: "我是信息",
							noreadnum: 11
						},
						{
							userpic: "../../static/demo/userpic/13.jpg",
							username: "昵称4",
							time: "10:21",
							data: "我是信息",
							noreadnum: 11
						}
					];
					this.list = arr;
					uni.stopPullDownRefresh();
				}, 2000)
			},
			// 上拉加载
			loadmore() {
				if (this.loadtext != "上拉加载更多") {
					return;
				}
				// 修改状态
				this.loadtext = "加载中...";
				// 获取数据
				setTimeout(() => {
					//获取完成
					let obj = {
						userpic: "../../static/demo/userpic/13.jpg",
						username: "昵称4",
						time: "10:21",
						data: "我是信息",
						noreadnum: 11
					};
					this.list.push(obj);
					this.loadtext = "上拉加载更多";
				}, 1000);
				//this.tablist[this.tabIndex].loadtext="没有更多数据了";
			}
		},
		onPullDownRefresh() {
			this.getData()
		},
		onReachBottom() {
			// 上拉加载
			this.loadmore();
		},
		onNavigationBarButtonTap(e) {
			if (e.index == 0) {
				console.log(111);
				uni.navigateTo({
					url: '../user-list/user-list',
				});
				this.hiddenPopup()
			} else {
				this.showPopup()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.body {
		padding: 0 20upx;
	}
</style>
